#!/usr/bin/env bash
set -e

# Build and copy ace, ace-uncompressed to RStudio
cd rstudio-ace

# Build ace. Note that we pass an explicit larger stack size to accommodate
# https://github.com/ajaxorg/ace/issues/4596.
NODEJS="$(command -v nodejs &> /dev/null && echo nodejs || echo node)"
${NODEJS} --stack_size=2048 ./Makefile.dryice.js normal
${NODEJS} --stack_size=2048 ./Makefile.dryice.js -m normal

cp build/src/ace.js ../../src/org/rstudio/studio/client/workbench/views/source/editors/text/ace/ace-uncompressed.js
cp build/src-min/ace.js ../../src/org/rstudio/studio/client/workbench/views/source/editors/text/ace/ace.js

# Copy in the 'emacs', 'vim' keybindings
cp build/src/keybinding-vim.js ../../src/org/rstudio/studio/client/workbench/views/source/editors/text/ace/keybinding-vim-uncompressed.js
cp build/src/keybinding-emacs.js ../../src/org/rstudio/studio/client/workbench/views/source/editors/text/ace/keybinding-emacs-uncompressed.js
cp build/src-min/keybinding-* ../../src/org/rstudio/studio/client/workbench/views/source/editors/text/ace/

# Copy the ext-language-tools
cp build/src/ext-language_tools.js ../../src/org/rstudio/studio/client/workbench/views/source/editors/text/ace/ext-language_tools-uncompressed.js
cp build/src-min/ext-language_tools.js ../../src/org/rstudio/studio/client/workbench/views/source/editors/text/ace/ext-language_tools.js

# Copy in workers
cp build/src-min/worker-html.js ../../www/js/workers
cp build/src-min/worker-css.js ../../www/js/workers
cp build/src-min/worker-javascript.js ../../www/js/workers

cd ..

